define([
  'models/AlertMessage',
  'views/Item',
  'views/Modal',
  'views/ConfirmCancelModal',
  'views/internals/UserModal',
  'hbs!template/internals/user-item',
  'hbs!template/internals/confirm-delete-internal-modal',
  'hbs!template/internals/success-internal-destroy'
], function(AlertMessage, ItemView, Modal, ConfirmCancelModal, UserModal, template, confirmTemplate, successDestroyTemplate){
  var UserItem = ItemView.extend({
	tagName: "tr",
	  
    events: {
      "click a[name=edit]":		"edit",
      "click a[name=delete]":		"confirmMessage"
    },
    
    initItem: function(options) {
      this.template = template;
      if(this.model) {
        this.model.bind("confirm_remove", this.confirm, this);
        this.model.bind("success_destroy", this.successDestroy, this);
      }
    },

    edit: function() {
      var modal = new UserModal({model: this.model});
      modal.render();
    },

    confirmMessage: function() { // TODO
      var modal = new ConfirmCancelModal({
        model: this.model,
        template: confirmTemplate});
      modal.render();

      /*  var message = new AlertMessage({model: this.model, title: "Esta seguro que desea eliminar el subscriptor?", about: this.model});
          this.addMessage(message); */
    },
    
    successDestroy: function() {
      var modal = new Modal({template: successDestroyTemplate});
      modal.render();
      this.remove();
    },
    
    confirm: function() {
      this.model.destroy();
    },
    
/*    remove: function() {
      this.$(this.el).remove();
    }
  */  
  });

  return UserItem;
});